home *** CD-ROM | disk | FTP | other *** search
/ PC World Komputer 2010 April / PCWorld0410.iso / pluginy Firefox / 2410 / 2410.xpi / chrome / content / shared / passwordmeter.js < prev   
Text File  |  2010-01-28  |  8KB  |  206 lines

  1.  
  2. /* ************************************************************
  3. Created: 20060120
  4. Author:  Steve Moitozo <god at zilla dot us> -- geekwisdom.com
  5. Description: This is a quick and dirty password quality meter 
  6.          written in JavaScript so that the password does 
  7.          not pass over the network.
  8. License: MIT License (see below)
  9. Modified: 20060620 - added MIT License
  10. Modified: 20061111 - corrected regex for letters and numbers
  11.                      Thanks to Zack Smith -- zacksmithdesign.com
  12. ---------------------------------------------------------------
  13. Copyright (c) 2006 Steve Moitozo <god at zilla dot us>
  14.  
  15. Permission is hereby granted, free of charge, to any person 
  16. obtaining a copy of this software and associated documentation 
  17. files (the "Software"), to deal in the Software without 
  18. restriction, including without limitation the rights to use, 
  19. copy, modify, merge, publish, distribute, sublicense, and/or 
  20. sell copies of the Software, and to permit persons to whom the 
  21. Software is furnished to do so, subject to the following 
  22. conditions:
  23.  
  24.    The above copyright notice and this permission notice shall 
  25. be included in all copies or substantial portions of the 
  26. Software.
  27.  
  28. THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY 
  29. KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE 
  30. WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE 
  31. AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT 
  32. HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, 
  33. WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING 
  34. FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE 
  35. OR OTHER DEALINGS IN THE SOFTWARE. 
  36. ---------------------------------------------------------------
  37.  
  38.  
  39. Password Strength Factors and Weightings
  40.  
  41. password length:
  42. level 0 (3 point): less than 4 characters
  43. level 1 (6 points): between 5 and 7 characters
  44. level 2 (12 points): between 8 and 15 characters
  45. level 3 (18 points): 16 or more characters
  46.  
  47. letters:
  48. level 0 (0 points): no letters
  49. level 1 (5 points): all letters are lower case
  50. level 2 (7 points): letters are mixed case
  51.  
  52. numbers:
  53. level 0 (0 points): no numbers exist
  54. level 1 (5 points): one number exists
  55. level 1 (7 points): 3 or more numbers exists
  56.  
  57. special characters:
  58. level 0 (0 points): no special characters
  59. level 1 (5 points): one special character exists
  60. level 2 (10 points): more than one special character exists
  61.  
  62. combinatons:
  63. level 0 (1 points): letters and numbers exist
  64. level 1 (1 points): mixed case letters
  65. level 1 (2 points): letters, numbers and special characters 
  66.                     exist
  67. level 1 (2 points): mixed case letters, numbers and special 
  68.                     characters exist
  69.  
  70.  
  71. NOTE: Because I suck at regex the code might need work
  72.       
  73. NOTE: Instead of putting out all the logging information,
  74.       the score, and the verdict it would be nicer to stretch
  75.       a graphic as a method of presenting a visual strength
  76.       guage.
  77.  
  78. ************************************************************ */
  79.  
  80. (function() {
  81.     function _TestPassword(passwd)
  82.     {
  83.             var intScore   = 0
  84.             var strVerdict = "weak"
  85.             var strLog     = ""
  86.             
  87.             // PASSWORD LENGTH
  88.             if (passwd.length<4)                         // length 4 or less
  89.             {
  90.                 intScore = (intScore+3)
  91.                 strLog   = strLog + "3 points for length (" + passwd.length + ")\n"
  92.             }
  93.             else if (passwd.length>4 && passwd.length<8) // length between 5 and 7
  94.             {
  95.                 intScore = (intScore+6)
  96.                 strLog   = strLog + "6 points for length (" + passwd.length + ")\n"
  97.             }
  98.             else if (passwd.length>7 && passwd.length<16)// length between 8 and 15
  99.             {
  100.                 intScore = (intScore+12)
  101.                 strLog   = strLog + "12 points for length (" + passwd.length + ")\n"
  102.             }
  103.             else if (passwd.length>15)                    // length 16 or more
  104.             {
  105.                 intScore = (intScore+18)
  106.                 strLog   = strLog + "18 point for length (" + passwd.length + ")\n"
  107.             }
  108.             
  109.             
  110.             // LETTERS (Not exactly implemented as dictacted above because of my limited understanding of Regex)
  111.             if (passwd.match(/[a-z]/))                              // [verified] at least one lower case letter
  112.             {
  113.                 intScore = (intScore+1)
  114.                 strLog   = strLog + "1 point for at least one lower case char\n"
  115.             }
  116.             
  117.             if (passwd.match(/[A-Z]/))                              // [verified] at least one upper case letter
  118.             {
  119.                 intScore = (intScore+5)
  120.                 strLog   = strLog + "5 points for at least one upper case char\n"
  121.             }
  122.             
  123.             // NUMBERS
  124.             if (passwd.match(/\d+/))                                 // [verified] at least one number
  125.             {
  126.                 intScore = (intScore+5)
  127.                 strLog   = strLog + "5 points for at least one number\n"
  128.             }
  129.             
  130.             if (passwd.match(/(.*[0-9].*[0-9].*[0-9])/))             // [verified] at least three numbers
  131.             {
  132.                 intScore = (intScore+5)
  133.                 strLog   = strLog + "5 points for at least three numbers\n"
  134.             }
  135.             
  136.             
  137.             // SPECIAL CHAR
  138.             if (passwd.match(/.[!,@,#,$,%,^,&,*,?,_,~]/))            // [verified] at least one special character
  139.             {
  140.                 intScore = (intScore+5)
  141.                 strLog   = strLog + "5 points for at least one special char\n"
  142.             }
  143.             
  144.                                         // [verified] at least two special characters
  145.             if (passwd.match(/(.*[!,@,#,$,%,^,&,*,?,_,~].*[!,@,#,$,%,^,&,*,?,_,~])/))
  146.             {
  147.                 intScore = (intScore+5)
  148.                 strLog   = strLog + "5 points for at least two special chars\n"
  149.             }
  150.         
  151.             
  152.             // COMBOS
  153.             if (passwd.match(/([a-z].*[A-Z])|([A-Z].*[a-z])/))        // [verified] both upper and lower case
  154.             {
  155.                 intScore = (intScore+2)
  156.                 strLog   = strLog + "2 combo points for upper and lower letters\n"
  157.             }
  158.  
  159.             if (passwd.match(/([a-zA-Z])/) && passwd.match(/([0-9])/)) // [verified] both letters and numbers
  160.             {
  161.                 intScore = (intScore+2)
  162.                 strLog   = strLog + "2 combo points for letters and numbers\n"
  163.             }
  164.     
  165.                                         // [verified] letters, numbers, and special characters
  166.             if (passwd.match(/([a-zA-Z0-9].*[!,@,#,$,%,^,&,*,?,_,~])|([!,@,#,$,%,^,&,*,?,_,~].*[a-zA-Z0-9])/))
  167.             {
  168.                 intScore = (intScore+2)
  169.                 strLog   = strLog + "2 combo points for letters, numbers and special chars\n"
  170.             }
  171.         
  172.         
  173.             if(intScore < 16)
  174.             {
  175.             strVerdict = "very weak"
  176.             }
  177.             else if (intScore > 15 && intScore < 25)
  178.             {
  179.             strVerdict = "weak"
  180.             }
  181.             else if (intScore > 24 && intScore < 35)
  182.             {
  183.             strVerdict = "mediocre"
  184.             }
  185.             else if (intScore > 34 && intScore < 45)
  186.             {
  187.             strVerdict = "strong"
  188.             }
  189.             else
  190.             {
  191.             strVerdict = "stronger"
  192.             }
  193.         return intScore;    
  194.       //  document.forms.passwordForm.score.value = (intScore)
  195.       //  document.forms.passwordForm.verdict.value = (strVerdict)
  196.       //  document.forms.passwordForm.matchlog.value = (strLog)
  197.     }
  198.  
  199. if (typeof(window) != 'undefined' && window.Foxmarks) {
  200.     Foxmarks.provide('Foxmarks.ThirdParty.testPassword');
  201.     Foxmarks.ThirdParty.TestPassword = _TestPassword;
  202. } else {
  203.     TestPassword = _TestPassword;
  204. }
  205. })();
  206.